package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.RateSchemeDetailDao;
import com.fdb.efp.nls.service.domain.RateSchemeDetail;
import com.fdb.efp.nls.service.facade.RateSchemeDetailService;
import com.fdb.efp.nls.service.vo.RateSchemeDetailVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 利率方案配置明细表				<p>
 * @author fuzm
 * @date 2018-05-08
 */
@Service("rateSchemeDetailService")
public class RateSchemeDetailServiceImpl implements RateSchemeDetailService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(RateSchemeDetailServiceImpl.class);

	@Autowired
	private RateSchemeDetailDao rateSchemeDetailDao;
	
	/**
	 * 新增操作
	 */
	public int insertRateSchemeDetail(RateSchemeDetailVO inRateSchemeDetailVo) {
		logger.debug("当前新增数据为:"+ inRateSchemeDetailVo.toString());
		int num;
		try {
			RateSchemeDetail rateSchemeDetail = new RateSchemeDetail();
			beanCopy(inRateSchemeDetailVo, rateSchemeDetail);
			num = rateSchemeDetailDao.insertRateSchemeDetail(rateSchemeDetail);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(RateSchemeDetailVO inRateSchemeDetailVo) {
		logger.debug("当前删除数据条件为:"+ inRateSchemeDetailVo);
		int num;
		try {
			RateSchemeDetail rateSchemeDetail = new RateSchemeDetail();
			beanCopy(inRateSchemeDetailVo, rateSchemeDetail);
			num = rateSchemeDetailDao.deleteByPk(rateSchemeDetail);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRateSchemeDetailVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(RateSchemeDetailVO inRateSchemeDetailVo) {
		logger.debug("当前修改数据为:"+ inRateSchemeDetailVo.toString());
		int num;
		try {
			RateSchemeDetail rateSchemeDetail = new RateSchemeDetail();
			beanCopy(inRateSchemeDetailVo, rateSchemeDetail);
			num = rateSchemeDetailDao.updateByPk(rateSchemeDetail);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inRateSchemeDetailVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public RateSchemeDetailVO queryByPk(RateSchemeDetailVO inRateSchemeDetailVo) {
		
		logger.debug("当前查询参数信息为:"+ inRateSchemeDetailVo);
		try {
			RateSchemeDetail queryRateSchemeDetail = new RateSchemeDetail();
			beanCopy(inRateSchemeDetailVo, queryRateSchemeDetail);
			RateSchemeDetail queryRslRateSchemeDetail = rateSchemeDetailDao.queryByPk(queryRateSchemeDetail);
			if (Objects.nonNull(queryRslRateSchemeDetail)) {
				RateSchemeDetailVO outRateSchemeDetailVo = beanCopy(queryRslRateSchemeDetail, new RateSchemeDetailVO());
				logger.debug("当前查询结果为:"+ outRateSchemeDetailVo.toString());
				return outRateSchemeDetailVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/*
	 * 根据方案id和期限查询
	 */
	public RateSchemeDetailVO queryByschemeNoTerm(RateSchemeDetailVO rateSchemeDetailVo) {

        logger.debug("当前查询参数信息为:"+ rateSchemeDetailVo);
        RateSchemeDetailVO outRateSchemeDetailVo = null;
        try {
            RateSchemeDetail queryRslRateSchemeDetail = rateSchemeDetailDao.queryByschemeNoTerm(rateSchemeDetailVo);
            if (Objects.nonNull(queryRslRateSchemeDetail)) {
                outRateSchemeDetailVo = beanCopy(queryRslRateSchemeDetail, new RateSchemeDetailVO());
                logger.info("当前查询结果为:"+ outRateSchemeDetailVo.toString());
                return outRateSchemeDetailVo;
            } else {
                logger.info("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return outRateSchemeDetailVo;

	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RateSchemeDetailVO> queryAllOwner(RateSchemeDetailVO rateSchemeDetailVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<RateSchemeDetailVO> list = null;
		try {
			List<RateSchemeDetail> rateSchemeDetails = rateSchemeDetailDao.queryAllOwnerByPage(rateSchemeDetailVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ rateSchemeDetails.size());
			pageSet(rateSchemeDetails, rateSchemeDetailVo);
			list = (List<RateSchemeDetailVO>) beansCopy(rateSchemeDetails, RateSchemeDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RateSchemeDetailVO> queryAllCurrOrg(RateSchemeDetailVO rateSchemeDetailVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<RateSchemeDetail> rateSchemeDetails = rateSchemeDetailDao.queryAllCurrOrgByPage(rateSchemeDetailVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+rateSchemeDetails.size());
		List<RateSchemeDetailVO> list = null;
		try {
			pageSet(rateSchemeDetails, rateSchemeDetailVo);
			list = (List<RateSchemeDetailVO>) beansCopy(rateSchemeDetails, RateSchemeDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<RateSchemeDetailVO> queryAllCurrDownOrg(RateSchemeDetailVO rateSchemeDetailVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<RateSchemeDetail> rateSchemeDetails = rateSchemeDetailDao.queryAllCurrDownOrgByPage(rateSchemeDetailVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ rateSchemeDetails.size());
		List<RateSchemeDetailVO> list = null;
		try {
			pageSet(rateSchemeDetails, rateSchemeDetailVo);
			list = (List<RateSchemeDetailVO>) beansCopy(rateSchemeDetails, RateSchemeDetailVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
